﻿using System.Collections.Generic;
using System.Linq;
using CI.Models;
using CI.Models.Production;
using CI.Utility;
using CI.ViewModels.Diagramming;

namespace CI.ViewModels
{
    public class JobSelectorViewModel : ItemSelectorViewModelBase
    {
        private readonly List<Activity> _jobDescriptors = new List<Activity>();

        public JobSelectorViewModel(string groupName, DiagramViewModel parentViewModel) : base(groupName, parentViewModel)
        {
            _jobDescriptors.Add(Activity.BuyItems);
            _jobDescriptors.Add(Activity.Contract);
            _jobDescriptors.Add(Activity.Copying);
            _jobDescriptors.Add(Activity.Invention);
            _jobDescriptors.Add(Activity.Manufacturing);
            _jobDescriptors.Add(Activity.PlanetaryInteraction);
            _jobDescriptors.Add(Activity.ResearchingMaterialProductivity);
            _jobDescriptors.Add(Activity.ResearchingTimeProductivity);
            _jobDescriptors.Add(Activity.ReverseEngineering);
            _jobDescriptors.Add(Activity.SellItems);
            _jobDescriptors.Add(Activity.Store);
            _jobDescriptors.Add(Activity.Transport);

            AddItems(_jobDescriptors);
        }

        private void AddItems(IEnumerable<Activity> descriptors)
        {
            foreach (var desc in descriptors)
                Items.Add(desc);
        }

        protected override void ApplyFilter()
        {
            Items.Clear();
            AddItems(_jobDescriptors.Where(d => ActivityHelper.FormatActivity(d).IndexOf(FilterByName) > -1));
        }
    }
}
